package cn.tedu.csmall.business.service.impl;

import cn.tedu.csmall.business.service.IBusinessService;
import cn.tedu.csmall.commons.pojo.order.dto.OrderAddDTO;
import cn.tedu.csmall.order.service.IOrderService;
import io.seata.spring.annotation.GlobalLock;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class BusinessServiceImpl implements IBusinessService {

    //Dubbo调用order模块service的方法
    @DubboReference
    private IOrderService dubboOrderService;

    @Override
    //此注解相当于设置了分布式事物的起点 当前模块就是分布式事物中的TM 要么都执行 要不都不执行
    @GlobalTransactional
    public void buy(){
        //创建用于新增订单的DTO实体类orderAddDTO
        OrderAddDTO orderAddDTO=new OrderAddDTO();
        orderAddDTO.setUserId("UU777");
        orderAddDTO.setCommodityCode("PU202");
        orderAddDTO.setCount(100);
        orderAddDTO.setMoney(100);
        log.info("新增的订单信息为：{}",orderAddDTO);

        dubboOrderService.orderAdd(orderAddDTO);

    }

}
